package com.yxb.application.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.application.domain.TeacherApplication;
import com.yxb.application.service.ITeacherApplicationService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 家教申请Controller
 * 
 * @author 林德炫
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/application/application")
public class TeacherApplicationController extends BaseController
{
    @Autowired
    private ITeacherApplicationService teacherApplicationService;

    @GetMapping(value = "getApplicationByUserId/{userId}")
    public TeacherApplication getApplicationByUserId(@PathVariable("userId") Long userId)
    {
        return teacherApplicationService.getApplicationByUserId(userId);
    }
    /**
     * 查询家教申请列表
     */
    @PreAuthorize("@ss.hasPermi('application:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeacherApplication teacherApplication)
    {
        startPage();
        List<TeacherApplication> list = teacherApplicationService.selectTeacherApplicationList(teacherApplication);
        return getDataTable(list);
    }

    /**
     * 导出家教申请列表
     */
    @PreAuthorize("@ss.hasPermi('application:application:export')")
    @Log(title = "家教申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherApplication teacherApplication)
    {
        List<TeacherApplication> list = teacherApplicationService.selectTeacherApplicationList(teacherApplication);
        ExcelUtil<TeacherApplication> util = new ExcelUtil<TeacherApplication>(TeacherApplication.class);
        util.exportExcel(response, list, "家教申请数据");
    }

    /**
     * 获取家教申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('application:application:query')")
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") Long applicationId)
    {
        return success(teacherApplicationService.selectTeacherApplicationByApplicationId(applicationId));
    }

    /**
     * 新增家教申请
     */
    @PreAuthorize("@ss.hasPermi('application:application:add')")
    @Log(title = "家教申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherApplication teacherApplication)
    {
//        获取当前教员的用户id
        teacherApplication.setuserId(getUserId());
        return toAjax(teacherApplicationService.insertTeacherApplication(teacherApplication));
    }

    /**
     * 修改家教申请
     */
    @PreAuthorize("@ss.hasPermi('application:application:edit')")
    @Log(title = "家教申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherApplication teacherApplication)
    {
        return toAjax(teacherApplicationService.updateTeacherApplication(teacherApplication));
    }

    /**
     * 根据userId修改教员申请状态
     */
    @Log(title = "家教申请", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatusByUserId/{userId}")
    public AjaxResult updateStatusByUserId(@PathVariable Long userId) {
        return toAjax(teacherApplicationService.updateApplicationStatusByUserId(userId));
    }

    /**
     * 删除家教申请
     */
    @PreAuthorize("@ss.hasPermi('application:application:remove')")
    @Log(title = "家教申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applicationIds}")
    public AjaxResult remove(@PathVariable Long[] applicationIds)
    {
        return toAjax(teacherApplicationService.deleteTeacherApplicationByApplicationIds(applicationIds));
    }
}
